<#include "/common/easyui-css.html">
<#include "/common/easyui-js.html">
<#include "/common/loading.html">
<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>

<body class="easyui-layout">
<!-- 说明 字符串：Errorproject，作为替换字符串 -->
<div class="easyui-layout" style="width:100%;height:100%;">
	<!-- 主表  -->
	<table id="project_table" class="easyui-treegrid" title="" style="width:100%;height:100%;padding-bottom: 2px;"
		   data-options="rownumbers:true, pagination:true,singleSelect:true,url:'/errorproject-list/N/1/20',
					  method:'get',
					  toolbar:'#tb',
					  idField: 'id',
					  animate: true,
                   lines:true,
                   onLoadSuccess:function(data){
                        $('.uuid').linkbutton({plain:true,iconCls:'icon-new'});
                        $('.delete').linkbutton({plain:true,iconCls:'icon-remove'});
                        $('.upload').linkbutton({plain:true,iconCls:'icon-upload'});
                    },
                   treeField: 'projectName',
					  loadMsg : '数据加载中',				 
					  showFooter: true" >
        <thead>
            <tr>
                <#--detail判断是否有文件-->
                <th data-options="field:'uuid',width:40,align:'left', formatter: uuidfile"></th>
                <th data-options="field:'projectName',width:200,align:'left'  ">项目名称</th>
                <th data-options="field:'errorReason',width:200,align:'center' ">异常原因</th>
                    <th data-options="field:'stage',width:200,align:'center' ">异常所处阶段</th>
                <th data-options="field:'proId',width:150,align:'center' ">项目编号</th>
                <#---->
                <th data-options="field:'id',width:100,align:'center' ,formatter: idFormatter ">操作</th>
                <th data-options="field:'_parentId',width:100,align:'center',hidden: 'true'"></th>
                <th data-options="field:'realId',width:100,align:'center',hidden: 'true'"></th>
                <th data-options="field:'vetoFlag',width:100,align:'center',hidden: 'true'"></th>
            </tr>
        </thead>
	</table>
</div>

<!-- 搜索框 -->
<div id="tb" style="padding:5px;height:auto">
	<div>
        项目名称:
        <input class="easyui-textbox" name="projectName"id="projectName">
		<a href="#" class="easyui-linkbutton" iconCls="icon-search" id="searchByParameter">搜索</a>
	</div>
    <div style="margin:5px 0;"></div>
    <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'" id="add">新增</a>
    <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-edit'" id="edit">修改</a>
    <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-accept'" id="accept">反馈</a>
    <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-remove'" id="remove">删除</a>
    <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-download'"  id="export">导出</a>
</div>

<script type="text/javascript">
    $("#searchByParameter").click(function(){
        var projectName = $("#projectName").val();
        var handler = '/errorproject-list/N/1/20?projectName='+projectName;
        $('#project_table').treegrid('options').url = handler;
        $('#project_table').treegrid('reload');
    });
</script>

<script type="text/javascript">

    function idFormatter(value,row) {
        var button = '';
        if(typeof(row._parentId)=="undefined") {
            return button;
        }
        button += '<a href="#" class="delete" title="删除" onclick=\'del(' + row.uuid + ')\'></a>';
        button += '<a href="#" class="upload" title="上传" onclick=\'upload_info(' +'\"'+ row._parentId + '\"'+ ',' + row.uuid + ')\'></a>';
        return button;
    }

    //value:detailId
    function uuidfile(value){
        var result = '';
        $.ajax({
            url : '/errorproject-has-file/'+value+'/YC',
            async : false,
            success :function (data) {
                result = data;
            }
        })
        var button = '';
        if(result){
            button += '<a href="#" class="uuid" title="文件已经上传" onclick="uidFile(\''+value+'\')"></a>';
        }
        return button;
    }
    //value : detailID
    function uidFile(value){
        var url = '/errorproject-files-show/'+value+'/YC';
        var index = layer.open({
            title: false,
            type: 2,
            area: ['900px', '450px'],
            fixed: true, //不固定
            maxmin: true,
            content: url
        });
    }

    function  del(val) {
        var row = $('#project_table').treegrid('getSelected');
        parent.layer.confirm('你确定要删除此异常详情？', {
            btn: ['删除','取消'] //按钮
        }, function(){
            $.ajax({
                url : '/error-ins-upd-del',
                data : {id:val,tm:new Date().getTime(),deleteflag:'Y'},
                async: false,
                type : 'post',
                success :function () {
                    $('#project_table').treegrid('reload',row._parentId);
                }
            })
            parent.layer.closeAll('dialog');
        }, function(){
        });
    }

    // val是uuid  ,errorProjectDetailId：id
    function upload_info(val,id) {

        var url = '/errorProject-upload/'+val+'/'+'YC_'+Number(Number(id)-5000)+'/'+id;
        var index = parent.layer.open({
            title:'异常项目资料上传',
            type: 2,
            area: ['700px', '450px'],
            fixed: true, //不固定
            maxmin: true,
            content: url,
            end:function () {
                $('#project_table').treegrid('reload',val);
            },
        });
    }

</script>

<!-- 按钮操作 -->
<script type="text/javascript">
	$("#add").click(function () {
        var row = $('#project_table').treegrid('getSelected');
        if (row&&row.relation=='parent'){
            var id = row.realId;
            var url = '/error-detail-add/'+id;
            var index = parent.layer.open({
                title:'异常项目，新增异常原因',
                type: 2,
                area: ['950px', '650px'],
                fixed: true, //不固定
                maxmin: true,
                content: url,
                end:function () {
                    $('#project_table').treegrid('reload',row.id);
                }
            });
        } else{
            parent.layer.msg("请选择增加异常原因的异常项目")
        }
    });
	$("#edit").click(function () {
        var row = $('#project_table').treegrid('getSelected');
        if (row&&row.relation=='son'){
            var id = row.uuid;
            var url = '/error-detail-edit/'+id;
            var index = parent.layer.open({
                title:'异常项目，异常原因修改',
                type: 2,
                area: ['950px', '650px'],
                fixed: true, //不固定
                maxmin: true,
                content: url,
                end:function(){
                    $('#project_table').treegrid('reload',row._parentId);
                }
            });

        } else{
            parent.layer.msg("请选择需要修改信息")
        }
    });
	$("#accept").click(function () {
        var row = $('#project_table').treegrid('getSelected');
        if (row&&row.relation=='son'){
            var id = Number(row.id);
            var url = '/error-ins-upd-del';
            layer.prompt({title: '对此项目进行结果反馈', formType: 2}, function(text, index){
                layer.close(index);
                var node = $('#project_table').treegrid('getSelected');
                $.ajax({
                    type :'post',
                    url : url,
                    data : {feedBack:text,id:id},
                    async :false,
                    success :function(){
                        $('#project_table').treegrid('reload',row._parentId);
                    }
                });
            });
        } else{
            parent.layer.msg("请选择需要进行反馈的信息")
        }
    });

	$("#remove").click(function () {
        var row = $('#project_table').treegrid('getSelected');
        if (row&&row.relation=='son'){
            parent.layer.confirm('你确定要删除此异常信息？', {
                btn: ['删除','取消'] //按钮
            }, function(){
                $.ajax({
                    url : '/error-ins-upd-del',
                    data : {id:row.uuid,tm:new Date().getTime(),deleteflag:'Y'},
                    async: false,
                    type : 'post',
                    success :function () {
                        $('#project_table').treegrid('reload',row._parentId);
                    }
                })
                parent.layer.closeAll('dialog');
            }, function(){
            });
        } else{
            parent.layer.msg("请选择需要删除的异常信息")
        }

    });
	$('#export').click(function(){
        window.location = "/errorproject-download";
    });
</script>

<!-- 分页 -->
<script type="text/javascript">
	$(function(){
		var p = $('#project_table').treegrid('getPager');
		p.pagination({
			pageSize: 20, //每页显示的记录条数，默认为10
			pageList: [20, 40, 60], //可以设置每页记录条数的列表
			onSelectPage: function (pageNumber, pageSize) {
			    if(pageNumber==0){
			        pageNumber = 1;
                }
                var projectName = $("#projectName").val();
				var handler = '/errorproject-list/N/'+pageNumber+"/"+pageSize+"?projectName="+projectName;
				$('#project_table').treegrid('options').url = handler;
				$('#project_table').treegrid('reload');
			}
		});
	})
</script>

